<?php

namespace addons\oil\listener\order;

use addons\oil\exception\Exception;
use addons\sum\model\Config;
use addons\oil\model\Order;
use addons\sumprint\library\Service as PrinterService;
use app\admin\model\oil\Store as StoreModel;
use app\admin\model\sumprint\Printer as PrinterModel;

/**
 * 核销后操作
 */
class Hexiao
{

    // 订单核销后操作
    public function orderHexiaoAfter(&$params) {
        $order = $params['order'];
        //增加小票打印-核销订单
        $store=StoreModel::where('id',$order['store_id'])->find();
        $printer=PrinterModel::where('id',$store['printer_id'])->find();
        if($printer){
            $printer_aram=[];
            $printer_aram['origin_id']=$order['order_sn'];
            $last4 = substr($order['order_sn'], - 4);
            $printer_aram['order_sn_last4']=$last4;
            $printer_aram['machine_code']=$printer['machine_code'];
            $printer_aram['store_name']=$order['store_name'];
            //这里的订单时间是核销时间
            $order_ext = $order['ext_arr'];
            $hexiao_time=$order_ext['hexiao_time']??0;
            $printer_aram['order_time']=date('Y-m-d H:i:s',$hexiao_time);
            $printer_aram['order_sn']=$order['order_sn'];
            $printer_aram['gun_title']=$order['gun_title'];
            $printer_aram['fuel_name']=$order['fuel_name'];
            $printer_aram['fuel_price']=$order['fuel_price'];
            $printer_aram['fuel_guaji_price']=$order['fuel_guaji_price'];
            $printer_aram['litre']=$order['litre'];
            $printer_aram['goods_amount']=$order['goods_amount'];
            $printer_aram['dispatch_amount']=$order['dispatch_amount'];
            $printer_aram['discount_fee']=$order['discount_fee'];
            $printer_aram['total_fee']=$order['total_fee'];
            $printer_aram['version']=$order['version'];
            $template_slug="oil_hexiao";
            PrinterService::submit($printer_aram,$template_slug);
        }
    }

}
